<%template _header%>
<!--TheCurrent start-->
<div id="foruminfo">
	<div class="userinfo">
		<h2><a href="{Config.WebsiteUrl}">{Config.WebsiteTitle}</a> <strong>用户注册</strong></h2>
	</div>
</div>
<!--TheCurrent end-->

<!--reg start-->

<%if ErrorCount>0%>

		<%template _errmsgbox%>
		
<%else%>

<%if {agree}!="1" %>

<form id="form1" name="form1" method="post" action="Register.aspx?agree=1">	
	<div class="ntforumbox">
		<div class="titlebar">
				<h3>用户注册协议</h3>
		</div>
		<table cellpadding="0" cellspacing="0" border="0">
			<tbody>
			<tr class="list"><td>
				<textarea name="textarea" cols="" rows="" readonly="readonly" class="colorblue" style="width:700px;height:320px;margin:10px 0;">{Config.RulesTxt}</textarea>
			</td></tr>
			</tbody>
			<tbody>
				<tr class="list">
						<td  style="padding:2px;">
					  <input name="agree" disabled="disabled" type="submit" id="agree" value="我同意" class="sbutton" />
					  &nbsp;&nbsp;
					  <input name="cancel" type="button" id="cancel" value="不同意" onClick="javascript:location.replace('index.aspx')" class="sbutton" />
					  
						<script type="text/javascript">
						var secs = 5;
						var wait = secs * 1000;
						document.getElementById("agree").value = "同 意(" + secs + ")";
						document.getElementById("agree").disabled = true;
						for(i = 1; i <= secs; i++) {
								window.setTimeout("update(" + i + ")", i * 1000);
						}
						window.setTimeout("timer()", wait);
						function update(num, value) {
								if(num == (wait/1000)) {
										document.getElementById("agree").value = "同 意";
								} else {
										printnr = (wait / 1000) - num;
										document.getElementById("agree").value = "同 意(" + printnr + ")";
								}
						}
						function timer() {
								document.getElementById("agree").disabled = false;
								document.getElementById("agree").value = "同 意";
						}
						</script>
						 </td>
			  </tr>
			</tbody>
		 </table>
	</div>
</form>

<%else%>
	
<%if {createUser}!="1" %>

<script type="text/javascript">
	
	var usernameok = false;
	var emailok = false;
	var pwdok = false;
	var pwd1ok = false;
	var termok = false;
	
	function CheckForm()
	{
	   if(usernameok == false) usernameok = checkusername();	
	   if(emailok == false) emailok = checkEmail();
	   if(pwd1ok == false) pwd1ok = checkpwd1();
	   if(pwdok == false) pwdok = checkpwd2();
	   if(usernameok && emailok && pwd1ok && pwdok){ 
	      var f = $("regform");
	      f.submit();
	    }
	}
	
	function checkusername()
	{
  		var username = document.getElementById("username").value;
			var unlen = username.replace(/[^\x00-\xff]/g, "**").length;

			if(unlen > 20)
			{
				$("usernameResult").innerHTML = "<font color='#009900'>对不起，您的用户名超过 20 个字符</font>";
				usernameok = false;
				return false;
			}
			else if(unlen < 3) 
			{
				$("usernameResult").innerHTML = "<font color='#009900'>对不起，您输入的用户名小于3个字符</font>";
				usernameok = false;
				return false;
			}
			
			$("usernameResult").innerHTML = "正在检查，请稍候....";
			var aurl = "/tools/userajax.aspx?f=chkusr&usr=" + escape(username);
			var myAjax = new Ajax(aurl, 
			   {
			   	  method: 'get',
			   	  onComplete: function()
			   	  {
			   	  	var result = this.response.text;
			   	  	if (result == "0"){
			   	  	    $("usernameResult").innerHTML = "可用";
			   	  	    usernameok = true;
			   	  	    return true;
			   	    }
			   	    else{
			   	    	  $("usernameResult").innerHTML = "<font color='#009900'>对不起，您输入的用户名不可用。</font>";
			   	    	  usernameok = false;
			   	    	  return false;
			   	    }
			   	  }
			   }
  	  );
			myAjax.request();
			return false;
	}

		
		
		function checkEmail()
		{
			var email = document.getElementById("email").value;
			var emailrex = /^\w+([-+.]\w+)*@\w+([-.]\\w+)*\.\w+([-.]\w+)*$/;
			
			var unlen = email.replace(/[^\x00-\xff]/g, "**").length;
			if(emailrex.test(email)==false)
			{
				$("emailResult").innerHTML = "<font color='#009900'>请输入正确的邮箱</font>";
				emailok = false;
				return;
			}
			$("emailResult").innerHTML = "正在检查，请稍候....";
			var aurl = "/tools/userajax.aspx?f=chkemail&email=" + escape(email);
			var myAjax = new Ajax(aurl, 
			   {
			   	  method: 'get',
			   	  onComplete: function()
			   	  {
			   	  	var result = this.response.text;
			   	  	if (result == "0"){
			   	  	    $("emailResult").innerHTML = "可用";
			   	  	    emailok = true;
			   	    }
			   	    else{
			   	    	  $("emailResult").innerHTML = "<font color='#009900'>对不起，您输入的邮箱不可用。</font>";
			   	    	  emailok = false;
			   	    }
			   	  }
			   }
  	  );
			myAjax.request();
			return false;
		}
		
	  function checkpwd1()
	  {
	  	  var pwd1 = $("password").value;
	  	  if(pwd1 == "") {
			  	$("pwdResult").innerHTML = "<font color='#009900'>请输入密码</font>";
			  	pwd1ok = false;
			  	return false;
			  }
			  else if(pwd1.length < 6){
			  	$("pwdResult").innerHTML = "<font color='#009900'>不得少于6个字符</font>";
			  	pwd1ok = false;
			  	return false;
			  }
			  pwd1ok = true;
			  $("pwdResult").innerHTML = "";
			  return true;
	  }
		
		function checkpwd2()
		{
			  $("pwd2Result").innerHTML= "";
			  if(pwd1ok == false) return false;
			  
			  var pwd1 = $("password").value;
			  var pwd2 = $("password2").value;
			  document.getElementById("pwd2Result").innerHTML = "";
			  
			  if(pwd1 != pwd2)
			  {
			  	$("pwd2Result").innerHTML = "<font color='#009900'>两次输入的密码不一致</font>";
			  	pwdok = false;
			  	return false;
			  }
			  
			  pwdok = true;
			  return true;
		}
		
		function checkterm()
		{
		}
	
	
</script>
	
<form id="regform" name="regform" method="post" action="/Register.aspx?agree=1&createuser=1">
	
  <div class="ntforumbox">
  	
	<div class="titlebar">
		<h3>填写注册信息</h3>
	</div>
	
	<div class="forumform">
		
	<table cellpadding="0" cellspacing="0" border="0">
	
	<tbody>
	<tr class="list">
				<th class="formlabel">用户名:</th>
				<td class="formbody">
					<input name="username" type="text" id="username" maxlength="20" size="30" class="colorblue" onfocus="this.className='colorfocus';" onblur="this.className='colorblue';checkusername();" />
					<span id="usernameResult">不超过20个字符</span>
				</td>
	</tr>
	</tbody>
	
	<tbody>
	<tr class="list">
				<th class="formlabel"><span>Email:</span></th>
				<td class="formbody"><input name="email" type="text" id="email" size="30" class="colorblue" onfocus="this.className='colorfocus';" onblur="this.className='colorblue';checkEmail();" />
					<span id="emailResult"></span>
				</td>
	</tr>
	</tbody>
	
	<tbody>
	<tr class="list">
				<th class="formlabel">密码:</th>
				<td class="formbody">
					<input name="password" type="password" id="password" size="30" class="colorblue" onfocus="this.className='colorfocus';" onblur="this.className='colorblue'; checkpwd1();"/>
					<span id="pwdResult">不得少于6个字符</span>
				</td>
	</tr>
	</tbody>
	
	<tbody>
	<tr class="list">
				<th class="formlabel"><span>重复输入密码:</span></th>
				<td class="formbody">
					<input name="password2" type="password" id="password2" size="30" class="colorblue" onfocus="this.className='colorfocus';" onblur="this.className='colorblue'; checkpwd2();" />
					<span id="pwd2Result"></span>
		    </td>
	</tr>
	</tbody>
	
	<tbody>
	<tr class="list">
				<th class="formlabel"><span>用户类型:</span></th>
				<td class="formbody">
					<input type="radio" name="userType" value="1" checked="checked"/> 病人
					<input type="radio" name="userType" value="2"/> 医生
					<span id="userTypeResult"></span>
		    </td>
	</tr>
	</tbody>	
		
 	<tbody>
		<tr class="list">
			<td colspan="2" class="formarea">
						<input name="btnSubmit" type="button" onclick="CheckForm();" class="sbutton" value="创建用户"/>  
						<input type="button" class="sbutton" onclick="javascript:window.location.replace('./index.aspx')" value="取消"/>
			</td>
		</tr>
	</tbody>
	</table>
	
	</div>
	
</form>

  <%else%>
  
  	   <%template _msgbox%>
	  
  <%/if%>

<%/if%>

<%/if%>
</div>
<%template _footer%>



                                                            